<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/${sysEname}/include/common-base.jsp"%>
  	<title>密码修改-${r'${titleName}'}</title>
	<script src="${r'${ctx}'}/common/plateform/base/utils/jquery-md5-min.js"></script>
	<script src="${r'${ctx}'}/js/uct/uc.js"></script>
</head>
<body  class="hold-transition ${r'${sysUserColor}'} sidebar-mini">

<div class="wrapper">

 <!-- top start -->
  <%@include file="/common/${sysEname}/top-user.jsp" %>
  <!-- top end -->
  <!-- left start -->
  <%@include file="/common/${sysEname}/left-user.jsp" %>
  <!-- left end -->

	<div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
 <div class="panel">
  	<div class="panel-heading">
  		<h4 class="fx2"><i class="fa fa-user-plus"></i> 密码修改</h4>
  	</div>
  	<div class="panel-body">
        <form id="myForm"  method="post" action="javascript:;">
			<input type="hidden" id="userid" name="userid" value="${r'${loginUser.userId}'}"/>
			<input type="hidden" id="username" name="username" value="${r'${loginUser.userEname}'}"/>
			<input type="hidden" name="oldPassHist" value="${r'${loginUser.userPass}'}"/>
			<input type="hidden" name="checkUserPass" value="1" />
			<input type="hidden" name="userPass" id="userPass" />
			<input type="hidden" name="newPass" id="newPass" />
			<input type="hidden" name="newPass2" id="newPass2" />

         <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table table-bordered">
            <tr>
              <th style="width:140px;" class="text-right">用户名：</th>
              <td><span class="col-sm-4">${r'${loginUser.userEname}'}</span></td>
            </tr>
			<tr class="isupdPass">
	              <th  class="text-right">旧密码：</th>
	              <td>
	              	<div class="col-sm-4 form-group">
	              		<input class="form-control" type="password"  name="oldPass" placeholder="输入旧密码" data-bv-notempty="true" data-bv-notempty-message="旧密码不能为空"/>
	              	</div>
	              </td>
	            </tr>
	            <tr class="isupdPass">
	              <th  class="text-right">新密码：</th>
	              <td>
					  <div class="col-sm-4 form-group">
	              		<input class="form-control" type="password" name="newPassw1" placeholder="输入新密码" data-bv-notempty="true" data-bv-notempty-message="新密码不能为空"/>
					  </div>
	              </td>
	            </tr>
	            <tr class="isupdPass">
	              <th  class="text-right">确认新密码：</th>
	              <td>
	              	<div class="col-sm-4 form-group">
	              		<input class="form-control" type="password" name="newPassw2" placeholder="再次输入新密码" data-bv-notempty="true" data-bv-notempty-message="确认新密码不能为空"/>
	              	</div>
	              </td>
	            </tr>
	            <tr>
	              <th  class="text-right">验证码：</th>
	              <td>
					<div class="col-xs-3 form-group">
						<input  class="form-control"  type="text" style="width:170px;" name="rand" maxlength="4" data-bv-notempty="true" data-bv-notempty-message="验证码不能为空" onclick="if(document.getElementById('verifyCode').style.visibility=='hidden'){viewVerifyCode();}"><img border=0 id="verifyCode" src="" onclick="viewVerifyCode();" style="visibility:hidden;" align="absmiddle"/>
					</div>
					  <div class="col-xs-4">
						<script>viewVerifyCode();</script>
					  </div>
				   </td>
	            </tr>
				<tr>
				<td>&nbsp;</td>
				<td align="left">
					<div class="col-xs-5">
						<input type="button" onclick="doSumbit()"  name="button" id="button"  class="btn btn-danger" value="提交保存"/>
					</div>
					</td>
				</tr>
          </table>
        </form>

        <!--表单结束 -->
      </div>
    </div>
    <!--主体内容结束-->
   </section>
		<script>
            var clickMenu = "my-user-edit-pass";
            var formId = "#myForm";
            $(function(){
                setValidate(formId);//定义add表单验证属性
                mytools.cleanValidate(formId);//清空上次校验规则提示
            });

            function doSumbit(){
                //校验规则-表单提交时触发
                var validate = $(formId).data('bootstrapValidator').validate();
                if(!validate.isValid()){ //如果校验不通过就返回
                    return;
                }
                var oldPass = $(formId).find("input[name='oldPass']").val();
                var oldPassHist = $(formId).find("input[name='oldPassHist']").val();
                if(oldPass.md5()!=oldPassHist){
                    layer.tips('输入的旧密码有误！', $(formId).find("input[name='oldPass']"), {tips: 3});
                    return;
                }
                var userPass1 = $(formId).find("input[name='newPassw1']").val();
                var userPass2 = $(formId).find("input[name='newPassw2']").val();
                if(userPass1!=userPass2){
                    layer.tips('两次输入密码不一致！', $(formId).find("input[name='newPass2']"), {tips: 3});
                    return;
                }
                $("#userPass").val(oldPass.md5());
                $("#newPass").val(userPass1.md5());
                $("#newPass2").val(userPass1.md5());

                var index_submit = layer.confirm('您确定要保存修改信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
                    , function(){
                        var index_load = layer.load(1, {shade: false});
                        $.ajax({
                            type:'post',
                            url:ctx+'/res/uct/editPwd',
                            data:$(formId).serialize(),
                            dataType:'json',
                            success: function(myData){
                                console.log("edit",myData);
                                if(myData.flag=="T"){
                                    layer.alert("修改成功，请重新登录！");
                                    var result;
                                    $.ajax({url:ctx+'/res/uct/logout',type: 'POST',cache: false,async:false,dataType:'json',
                                        success: function(data){result = data;}
                                    });
                                    location.href=ctx+"/logout";
                                }else{
                                    viewVerifyCode();
                                    layer.alert(myData.msg);
                                }
                                layer.close(index_load);
                            },
                            error: function (e) {
                                layer.close(index_load);
                            }
                        });
                    });
            }
            function setValidate(id){
                $(id).each(function(){
                    $(this).bootstrapValidator({
                        feedbackIcons: {
                            valid: 'glyphicon glyphicon-ok',
                            invalid: 'glyphicon glyphicon-remove',
                            validating: 'glyphicon glyphicon-refresh'
                        },/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
                        fields:{
                            /** 可自定义新增验证规则**/
                            "newPassw2":{
                                validators: {
                                    identical: {
                                        field: 'newPassw1',
                                        message: '两次新密码不相同！'
                                    }
                                }
                            }

                        }
                    });
                });
            }
		</script>
  </div>
   <!-- foot start -->
  <%@include file="/common/${sysEname}/foot-user.jsp" %>
  <!-- foot start -->

</body>
</html>
